/*
*   Copyright (c) 2000 Martin Newstead (mseries@brundell.fsnet.co.uk).  All Rights Reserved.
*
*   The author makes no representations or warranties about the suitability of the
*   software, either express or implied, including but not limited to the
*   implied warranties of merchantability, fitness for a particular
*   purpose, or non-infringement. The author shall not be liable for any damages
*   suffered by licensee as a result of using, modifying or distributing
*   this software or its derivatives.
*
*   The author requests that he be notified of any application, applet, or other binary that
*   makes use of this code and that some acknowedgement is given. Comments, questions and
*   requests for change will be welcomed.
*/
package mseries.ui;

import mseries.Calendar.MDateChanger;
import mseries.Calendar.MDefaultPullDownConstraints;
import mseries.Calendar.MFieldListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;

public class MDateEntryFieldDemo3 implements Runnable
{

    JFrame frame, frame2;

    public static void main(String[] argv)
    {
        MDateEntryFieldDemo3 demo = new MDateEntryFieldDemo3();
        demo.run();
    }

    public void run()
    {

        //Locale.setDefault(new Locale("ru", "RU"));
        /*
        *   This block of code deals with placing the build number & date in the
        *   window title.
        */

        frame = new JFrame("Test Window ");

        frame.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });

        setLookAndFeel(UIManager.getSystemLookAndFeelClassName());


        frame2=new JFrame("Test Window");
        JButton b=new JButton("Push Me");
        frame.getContentPane().add(b);
        b.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                frame2.setVisible(true);
            }
        });
        frame.pack();


        /*****************************
         * The Demo code starts here  *
         *****************************/

        /*---------------- MDateEntryField ------------------*/
        Calendar cx = Calendar.getInstance();
        cx.set(2001, 5, 12);
        final MDateEntryField entryField = new MDateEntryField(10);

        MDefaultPullDownConstraints c = new MDefaultPullDownConstraints();
        c.firstDay = Calendar.MONDAY;
        c.changerStyle = MDateChanger.BUTTON;
        c.hasShadow = true;

        entryField.setConstraints(c);

        entryField.addMFieldListener(new MFieldListener()
        {
            public void fieldEntered(FocusEvent e)
            {
                System.out.println("MDateEntryField:Entered");
            }

            public void fieldExited(FocusEvent e)
            {
                System.out.println("MDateEntryField:Exited");
                try
                {
                    System.out.println("EE " + entryField.getValue());
                }
                catch (Exception ee)
                {
                    System.out.println(ee);
                }

            }
        });

        entryField.addMChangeListener(new MChangeListener()
        {
            public void valueChanged(MChangeEvent e)
            {
                System.out.println(e.getValue());
            }
        });

        entryField.setToolTipText("Click the button");


        /*---------------- Layout the frame ----------------*/
        GridLayout l = new GridLayout(3, 4, 7, 7);
        JPanel displayPanel = new JPanel(l);


        displayPanel.add(new JLabel("MDateEntryField"));
        displayPanel.add(entryField);

        frame2.getContentPane().setLayout(new FlowLayout());
        frame2.getContentPane().add(displayPanel);


        frame2.pack();
        frame.show();
    }

    public void setLookAndFeel(String laf)
    {
        try
        {
            UIManager.setLookAndFeel(laf);
            SwingUtilities.updateComponentTreeUI(frame);
            frame.pack();
        }
        catch (Exception ex)
        {
            System.out.println("Failed loading L&F: " + laf);
            System.out.println(ex);
        }
    }
}


